using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class BtnEffSize : MonoBehaviour
{
    public List<ParticleSystem> particleList_life;
    public ParticleSystem[] particleList_size;

    //public Canvas targetCanvas;
    //public ParticleSystem.MainModule mainModule;

    //public const float canvasDistance = 110;
    public const int defaultW = 1920;
    public const int defaultH = 1080;
    public const float defaultRatio = defaultW / (float)defaultH;

    int screenHeight, screenWidth;

    public float mSize;

    //void Start()
    void Awake()
    {
        mSize = 1f;
        //targetCanvas = GetComponentInParent<Canvas>();

        screenHeight = Screen.height;
        screenWidth = Screen.width;

        mSize = (float)screenWidth / (screenHeight * defaultRatio);
        if (mSize > 1) mSize = 1;

        SetLife();
        SetSize();
    }

    void SetSize()
    {
        particleList_size = GetComponentsInChildren<ParticleSystem>(true);

        if (particleList_size != null)
        {
            for (int i = 0; i < particleList_size.Length; i++)
            {
                particleList_size[i].startSize *= mSize;
                //particleList_size[i].main.startSize = mSize;

                //mainModule = particleList_size[i].main;
                //mainModule.startSize = mSize;
            }

        }
    }

    void SetLife()
    {
        if (particleList_life != null)
        {
            for (int i = 0; i < particleList_life.Count; i++)
            {
                particleList_life[i].startLifetime *= mSize;

                //mainModule = particleList_size[i].main;
                //mainModule.startLifetime = mSize;
            }
        }
    }
}
